home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / EnhanceMail.1.3 / Source / EnhanceMail.m < prev    next >
Encoding:
Text File  |  1996-04-08  |  4.6 KB  |  200 lines

  1. /* -*-C-*-
  2. *******************************************************************************
  3. *
  4. * File:         EnhanceMail.m
  5. * RCS:          $Header: /usr/local/lib/cvs/EnhanceMail/EnhanceMail.m,v 1.1.1.12 1996/04/08 22:30:51 cedman Exp $
  6. * Description:  
  7. * Author:       Carl Edman
  8. * Created:      Fri Oct 13 11:48:05 1995
  9. * Modified:     Mon Apr  8 11:09:31 1996 (Carl Edman) cedman@capitalist.princeton.edu
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       Experimental (Do Not Distribute)
  13. *
  14. * (C) Copyright 1995, but otherwise this file is perfect freeware.
  15. *
  16. *******************************************************************************
  17. */
  18.  
  19. #import "EnhanceMail.h"
  20. #import "Preferences.h"
  21. #import <ctype.h>
  22.  
  23. NXBundle *EnhanceBundle=0;
  24. char *EnhanceVersion="X";
  25. char *regerrval=0;
  26.  
  27. static const char *CVSName="$Name: release1_3 $";
  28. static BOOL windowsOnUnhide=NO;
  29.  
  30. BOOL EnhanceControlP(void)
  31.    {
  32.    NXEvent *ev=[NXApp currentEvent];
  33.    return ev && (ev->flags & NX_CONTROLMASK);
  34.    }
  35.  
  36. BOOL EnhanceShiftP(void)
  37.    {
  38.    NXEvent *ev=[NXApp currentEvent];
  39.    return ev && (ev->flags & NX_SHIFTMASK);
  40.    }
  41.  
  42. BOOL EnhanceAlternateP(void)
  43.    {
  44.    NXEvent *ev=[NXApp currentEvent];
  45.    return ev && (ev->flags & NX_ALTERNATEMASK);
  46.    }
  47.  
  48. @implementation EnhanceMail
  49. + finishLoading:(struct mach_header *)header
  50.    {
  51.    const char *beg=CVSName,*end=CVSName+strlen(CVSName);
  52.    
  53.    [self poseAs:[self superclass]];
  54.    [NXApp changeClassTo:[self class]];
  55.  
  56.    while((beg<=end) && !isdigit(*beg)) beg++;
  57.    while((beg<=end) && !isdigit(*end)) end--;
  58.    
  59.    if (beg<end)
  60.       {
  61.       char *c;
  62.  
  63.       end++;
  64.       EnhanceVersion=strncpy(malloc(end-beg+1),beg,end-beg);
  65.       EnhanceVersion[end-beg]='\0';
  66.       for(c=EnhanceVersion;*c;c++) if (*c=='_') *c='.';
  67.       }
  68.  
  69.    return self;
  70.    }
  71.  
  72. - initialCheck:sender
  73.    {
  74.    if ([self isHidden])
  75.       {
  76.       windowsOnUnhide=YES;
  77.       }
  78.    else
  79.       {
  80.       if (EnhanceLaunchMailboxes) [NXApp mailboxes:self];
  81.       if (EnhanceLaunchAddresses) [NXApp address:self];
  82.       }
  83.    return [super initialCheck:sender];
  84.    }
  85.  
  86. - appDidUnhide:sender
  87.    {
  88.    if (windowsOnUnhide)
  89.       {
  90.       if (EnhanceLaunchMailboxes) [NXApp mailboxes:self];
  91.       if (EnhanceLaunchAddresses) [NXApp address:self];
  92.       windowsOnUnhide=NO;
  93.       }
  94.    return [super appDidUnhide:sender];
  95.    }
  96.  
  97. - (BOOL)updateCell:cell
  98.    {
  99.    return [super updateCell:cell];
  100.    }
  101. @end
  102.  
  103. @implementation Menu(EnhanceMail)
  104. - findCellWithTitle:(const char *)title
  105.    {
  106.    id cell=nil;
  107.    int x, y, rows, cols;
  108.    const char *c,*end;
  109.  
  110.    if (title==0) return nil;
  111.    for(end=title;(*end) && (*end!='/');end++);
  112.    
  113.    [matrix getNumRows:&rows numCols:&cols];
  114.    for(y=0;(y<rows) && (cell==nil);y++) for(x=0;(x<cols) && (cell==nil);x++)
  115.       {
  116.       if ((cell=[matrix cellAt:y:x])==nil) continue;
  117.       
  118.       if (((c=[cell title])==0)||(strncmp(title,c,end-title)!=0)||(c[end-title]!='\0'))
  119.          cell=nil;
  120.       }
  121.  
  122.    if (cell==nil)
  123.       return nil;
  124.    else if ((*end!='\0') && [cell hasSubmenu])
  125.       return [[cell target] findCellWithTitle:end+1];
  126.    else if (*end=='\0')
  127.       return cell;
  128.    else
  129.       return nil;
  130.    }
  131.  
  132. - addSlashItem:(const char *)title action:(SEL)sel keyEquivalent:(unsigned short)code
  133.    {
  134.    id cell=nil;
  135.    int x, y, rows, cols;
  136.    const char *c,*end;
  137.  
  138.    if (title==0) return nil;
  139.    for(end=title;(*end) && (*end!='/');end++);
  140.  
  141.    [matrix getNumRows:&rows numCols:&cols];
  142.    for(y=0;(y<rows) && (cell==nil);y++) for(x=0;(x<cols) && (cell==nil);x++)
  143.       {
  144.       if ((cell=[matrix cellAt:y:x])==nil) continue;
  145.       
  146.       if (((c=[cell title])==0)||(strncmp(title,c,end-title)!=0)||(c[end-title]!='\0'))
  147.          cell=nil;
  148.       }
  149.  
  150.    if ((cell==nil) && (*end=='\0'))
  151.       {
  152.       cell=[self addItem:title action:sel keyEquivalent:code];
  153.       [self display];
  154.       return cell;
  155.       }
  156.    else if (cell==nil)
  157.       {
  158.       char *d=alloca(end-title+1);
  159.       strncpy(d,title,end-title);
  160.       d[end-title]='\0';
  161.       cell=[self addItem:d action:0 keyEquivalent:0];
  162.       [self setSubmenu:[[Menu alloc] initTitle:d] forItem:cell];
  163.       [self display];
  164.       return [[cell target] addSlashItem:end+1 action:sel keyEquivalent:code];
  165.       }
  166.    else if ((*end!='\0') && [cell hasSubmenu])
  167.       return [[cell target] addSlashItem:end+1 action:sel keyEquivalent:code];
  168.    else if (*end=='\0')
  169.       return cell;
  170.    else
  171.       return nil;
  172.    }
  173. @end
  174.  
  175. @implementation Object(EnhanceMail)
  176. - changeClassTo:class
  177.    {
  178.    /* Don't try this at home, kids */
  179.    isa=class;
  180.    return self;
  181.    }
  182. @end
  183.  
  184. @implementation ButtonCell(EnhanceMail)
  185. - (int)state
  186.    {
  187.    return [self intValue];
  188.    }
  189.  
  190. - setState:(int)anInt
  191.    {
  192.    return [self setIntValue:anInt];
  193.    }
  194. @end
  195.  
  196. void regerror(char *s)
  197.    {
  198.    [NXApp logError:"regexp(3): %s",s];
  199.    }
  200.